<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
    <!--{include file='comm/header.tpl'}-->
    <title>组织机构</title>
    <!--引用div做成的下拉框效果样式-->
    <link rel="stylesheet" href="/quanliadmin/docroot/css/department_select.css" type="text/css" media="screen" />

</head>

<body>
<style>
    .fbutton .add {background: url("/framework/flexigrid/css/images/add.png") no-repeat scroll left center rgba(0, 0, 0, 0);}

    div.tDiv {
        width:80px;
        margin-bottom:2px;
        background: url("/framework/flexigrid/css/images/bg.gif") repeat-x scroll center top #EAEAEA;
        border-color: #CCCCCC #CCCCCC -moz-use-text-color;
        padding:5px;
    }

    #img_add_1,.add,a{cursor: pointer;}

    .tal{text-align: center;}

    #goods_table th{color:#666666;font-weight:bold;}

    #goods_table td{padding:8px;}

    #goods_table .left{float:left;}

    .closeImg{background:url('/quanliadmin/docroot/images/comm/category_icon.png') no-repeat -20px 0px; width:14px;height:14px;margin:8px 6px 0px 10px;cursor:pointer;}

    .openImg{background:url('/quanliadmin/docroot/images/comm/category_icon.png') no-repeat 0px 0px; width:14px;height:14px;margin:8px 6px 0px 10px;cursor:pointer;}

    .childImg{background:url("/quanliadmin/docroot/images/comm/category_icon.png") no-repeat 0px -18px;width:14px;height:14px;margin:0px 6px 0px 10px;cursor:pointer;}
    .childSelectImg{background:url("/quanliadmin/docroot/images/comm/category_icon.png") no-repeat 0px -18px;margin:0px 6px 0px 10px;cursor:pointer;}
    .point{ width:8px;height:14px;margin:8px 6px 0px 16px;}
    .nopoint{width:8px;height:14px;margin:8px 6px 0px 5px;}
    .childCategory{ width:16px;height:16px;background-image:url(/quanliadmin/docroot/images/comm/ImageBundle.gif);background-repeat:no-repeat;background-position:0 -14px;margin: 0 auto;cursor:pointer;}
    .editCategory{width:16px;height:16px;background-image:url(/quanliadmin/docroot/images/comm/ImageBundle.gif);background-repeat:no-repeat;background-position:0 -181px; margin-top: -17px;margin-left:34px;cursor:pointer;}

    .delcategory{width:16px;height:16px;background-image:url(/quanliadmin/docroot/images/comm/ImageBundle.gif);background-repeat:no-repeat;background-position:0 -133px;margin: 0 auto;cursor:pointer;}

    .big_f{ font-size: 18px;}
    .imageSite{
        position: absolute;
        left:280px;
        top:8px;
    }

</style>

<div class="container">

        <div class="comm_content">

            <div class="items2" id = "cate_table" style="margin:0px auto;width:94%;border-top:0px;">

                <div class="tDiv">
                    <div class="tDiv2">
                        <div class="fbutton">
                            <div>
                                <span class="add" style="padding-left: 20px;" onclick = 'userDepartment.add()'>添加组织</span>
                            </div>
                        </div>
                    </div>
                    <div style="clear:both"></div>
                </div>

                <table id="goods_table" class="s form-inline" style="width: 100%;margin: 0 auto 8px;">
                    <thead>
                    <tr>
                        <th width="*">部门名称</th>
                        <th width="100">修改
                        </th>
                        <th width="100">使用状态</th>
                        <th width="100">添加子部门</th>
                        <th width="100">删除</th>
                    </tr>
                    </thead>

                    <tbody>

                        <!--{$department_html}-->

                    </tbody>
                    </table>
                </div>

            </div>


<div id="pop" style="display: none;">
    <div style="width:100%; background: #ffffff">
        <form id = "tagGroup_form"  class="form-horizontal" onsubmit="return false;">

            <div class="form-group">
                <label class="col-sm-2 control-label" for="departmentName">
                    <span class="red">*</span>
                    部门名称：
                </label>
                <div class="col-sm-10">
                    <input id="pop_departmentName" class="form-control w300" type="text" placeholder="请输入部门名称" name="pop_departmentName">
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-2 control-label" for="sort">
                    <span class="red">*</span>
                    排序：
                </label>
                <div class="col-sm-10">
                    <input id="sort" class="form-control w150" type="text" placeholder="请输入排序" name="sort">
                </div>
            </div>

            <div class="form-group">
                <label for="departmentID" class="col-sm-2 control-label"><span class="red">*</span>上级部门：</label>
                <div class="col-sm-10">

                    <!--<select class="form-control w300 fl" name="departmentID" id="departmentID" >
                        <option value="0" selected="">顶级部门</option>
                        <!--$department_select_html}
                    </select>-->
                    <div class="search_option" style="clear:left;">
                        <div class="search_option_drop" >
                            <span id="searchOption" style="display:block;line-height:30px;">
                                    顶级部门
                                <font class="imageSite"><img src="/quanliadmin/docroot/images/comm/selects.jpg"></font>
                            </span>
                        </div>

                        <ul class="search_option_panel"  id="searchPanel" style="display: none;z-index: 100;clear:both;">
                            <li class="childSelectImg" departmentID="0" style="clear:both;margin-top:5px;margin-bottom:5px;margin-left: 0px;font-size: 13px;" >顶级部门</li>
                            <!--{$department_select_html}-->
                        </ul>

                        <input type="hidden" value="0" id="hdnSearchType" name="hdnSearchType">
                        <input type="hidden" value="" id="departmentID" name="departmentID">
                        <input type="hidden" value="" id="departmentName" name="departmentName">
                    </div>
                </div>
            </div>


            <div class="form-group" >
                <label class="col-sm-2 control-label" for="memo">
                    <span class="red">*</span>
                    备注：
                </label>
                <div class="col-sm-10">

                    <textarea id="memo" class="form-control w300" rows="3" name="memo"></textarea>

                </div>
            </div>

            <input type="hidden" name="useFlg" id="useFlg" value= "1" />
        </form>
    </div>

</div>



<script type="text/javascript">

function recursionOpen( deparmentID ) {
    var o = $('.deparment_line_'+ deparmentID);
    if ( o ) {
        $('#icon_' + deparmentID).removeClass('closeImg').addClass('openImg');
        $.each(o, function(k, v) {
            $(v).show();
            recursionOpen($(v).attr('cid'));
        });
    }
}

function recursionClose( deparmentID ) {
    var o = $('.deparment_line_'+ deparmentID);
    if ( o ) {
        $('#icon_' + deparmentID).removeClass('openImg').addClass('closeImg');
        $.each(o, function(k, v) {
            $(v).hide();
            recursionClose($(v).attr('cid'));
        });
    }
}

    var userDepartment = {
        departmentID:'', //部门id
        parentID:'', //上级部门id
        useFlg:'', // 禁用启用状态
        departmentName:'', //部门名称
        sort:'', //排序
        //更新使用状态
        changeUse : function(userDepartmentID, useFlg, level){

            this.userDepartmentID = userDepartmentID;
            this.useFlg = useFlg;
            this.level = level;

            if (useFlg == 0) {
                E.confirm("您确认要禁用此商品分类吗？", "userDepartment.useConfirm");
            } else {
                userDepartment.useConfirm();
            }
        },

        //确认修改分类使用状态
        useConfirm : function(){
            E.loadding.open('请稍等...');
            E.ajax_post({
                url : "/invokingAjax-backend/goods/userDepartment.ajax?operFlg=3",
                data : {'userDepartmentID' : this.userDepartmentID, 'useFlg' : this.useFlg, 'level' : this.level},
                call : 'userDepartment.result'
            });
        },

        //展示分类
        showuserDepartment : function(id,level) {
            if ($('#icon_' + id).hasClass('closeImg')) {
                recursionOpen( id );
            } else {
                recursionClose( id );
            }
        },

        //部门添加
        add: function( departmentID ) { // 有参数为添加子部门 无参数为顶部添加部门
            userDepartment.departmentID = departmentID;
            if(departmentID){
                $.ajax({
                    type: "POST",
                    url: "/invokingAjax-backend/system/userDepartment.ajax?operFlg=3" ,
                    dataType: "JSON",
                    data: {departmentID:departmentID},
                    success: function( result_obj ) {
                        if (result_obj.code == 200) {
                            var spanValues = result_obj.data ;
                            //var str = '<option readonly value='+departmentID +' > '+result_obj["data"]+'</option>';
                            $('.search_option_drop').find('span').attr('id','');
                            //$("#searchOption").text( '');
                            //var str = '<span  style="display:block;line-height:30px;">' +spanValues+ '</span>';
                            $('.search_option_drop').find('span').text( spanValues );
                        } else {
                            E.alert(result_obj.message);
                        }
                    }
                });
            }
            E.popup.open({
                id: "pop",
                title: "部门添加",
                css: "width:700px;",
                btnName: "保存",
                btnCall:"userDepartment.check();"
            });
        },

        //组织添加校验
        check: function() {

            this.dt = E.getFormValues("tagGroup_form");

            var error_msg = "";

            if (this.dt.pop_departmentName == "")
                error_msg += "部门名称不能为空<br>";

            if (this.dt.sort == ""){
                error_msg += "排序不能为空";
            }else if(!E.isNum(this.dt.sort)){
                error_msg += "排序必须为数字";
            }

            if (error_msg != "")
                E.alert(error_msg);
            else
                userDepartment.addSave() ;
        },

        //保存部门信息
        addSave: function() {
            E.loadding.open("执行中，请稍后...");
            this.dt.departmentID = userDepartment.departmentID;
            $.ajax({
                type: "POST",
                url: "/invokingAjax-backend/system/userDepartment.ajax?operFlg=1" ,
                dataType: "JSON",
                data:this.dt,
                success: function( result_obj ) {
                    E.loadding.close();
                    if (result_obj.code == 200) {
                        userDepartment.load();
                        E.alert(result_obj.message,2,"E.popup.close");
                    } else {
                        E.alert(result_obj.message);
                    }
                }
            });
        },

        //页面重新加载
        load: function() {
            self.location = '/quanliadmin/app/system/userDepartment.pscript?operFlg=1'
        },

        //禁用启用确认
        changeUse: function(departmentID,parentID,useFlg) {
            userDepartment.departmentID = departmentID;
            userDepartment.parentID = parentID;
            userDepartment.useFlg = useFlg;
            if( useFlg == 1 ){
                E.confirm("您确认 <b>禁用</b> 吗？", "userDepartment.statusChange");
            }else{
                E.confirm("您确认 <b>启用</b> 吗？", "userDepartment.statusChange");
            }

        },

        //禁用启用执行
        statusChange:function(){
            E.loadding.open("执行中，请稍后...");
            $.ajax({
                type: "POST",
                url: "/invokingAjax-backend/system/userDepartment.ajax?operFlg=2" ,
                dataType: "JSON",
                data: {departmentID:userDepartment.departmentID,parentID:userDepartment.parentID,useFlg:userDepartment.useFlg},
                success: function( result_obj ) {
                    E.loadding.close();
                    if (result_obj.code == 200) {
                        userDepartment.load();
                        E.alert(result_obj.message,2,"E.popup.close");
                    } else {
                        E.alert(result_obj.message);
                    }
                }
            });
        },

        //修改部门信息
        edit:function(departmentID){
            userDepartment.departmentID = departmentID;
            userDepartment.departmentName = $('#input_'+departmentID).val();
            userDepartment.sort = $('#sort_'+departmentID).val();
            E.confirm("您确认 <b>修改</b> 吗？", "userDepartment.editExecute");
        },

        //修改部门信息执行
        editExecute:function(){
            $.ajax({
                type: "POST",
                url: "/invokingAjax-backend/system/userDepartment.ajax?operFlg=4" ,
                dataType: "JSON",
                data: {departmentID:userDepartment.departmentID,departmentName:userDepartment.departmentName,sort:userDepartment.sort},
                success: function( result_obj ) {
                    E.loadding.close();
                    if (result_obj.code == 200) {
                        userDepartment.load();
                        E.alert(result_obj.message,2,"E.popup.close");
                    } else {
                        E.alert(result_obj.message);
                    }
                }
            });
        },

        //删除部门确认
        delDepartment : function(departmentID){
            userDepartment.departmentID = departmentID;

            E.confirm("您确认要删除此部门及下级部门吗？", "userDepartment.delConfirm");
        },

        // 删除执行
        delConfirm : function(){
            E.loadding.open('请稍等...');
            $.ajax({
                type: "POST",
                url: "/invokingAjax-backend/system/userDepartment.ajax?operFlg=5" ,
                dataType: "JSON",
                data: {departmentID:userDepartment.departmentID},
                success: function( result_obj ) {
                    E.loadding.close();
                    if (result_obj.code == 200) {
                        userDepartment.load();
                        E.alert(result_obj.message,2,"E.popup.close");
                    } else {
                        E.alert(result_obj.message);
                    }
                }
            });
        }


    }

</script>
        <!--引用div做成的下拉框效果js-->
        <script language="JavaScript" src="/quanliadmin/docroot/js/department_select.js" type="text/javascript"></script>
</body>

</html>
